
//
//  WorkTeamViewController.m
//  PASystem
//
//  工作团队
//
//

#import "WorkTeamViewController.h"
#import "WorkTeamCell.h"
#import "WorkModel.h"
#import "WorkPlanCell.h"
#import "AdvertisePlan.h"
#import "AdvertisePlanCell.h"

@interface WorkTeamViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,strong) NSMutableArray *dataArray;
@property (nonatomic,strong) NSMutableArray *dataArray1;
@property (nonatomic,strong) NSMutableArray *dataArray2;

@property (nonatomic,strong) UITableView *tab;

@property (nonatomic,strong) UITableView *tab2;

@property (nonatomic,strong) UITableView *tab3;


@end

@implementation WorkTeamViewController

static NSString *const ID = @"WorkTeamCell";

static NSString *const ID2 = @"WorkPlanCell";
static NSString *const ID3 = @"AdvertiseCell";

-(NSMutableArray *)dataArray{
    if (!_dataArray) {
        
        _dataArray = [NSMutableArray array];
    }

    return _dataArray;
}

- (NSMutableArray *)dataArray2{
    if (!_dataArray2) {
        _dataArray2 = [NSMutableArray array];
    }
    return _dataArray2;
}

- (NSMutableArray *)dataArray1{
    if (!_dataArray1) {
        
        _dataArray1 = [NSMutableArray array];
    }
    return _dataArray1;
}

- (void)viewDidLoad {
    [super viewDidLoad];

    self.view.backgroundColor = [UIColor colorWithRed:241/255.0 green:242/255.0 blue:243/255.0 alpha:1];

    UIScrollView *scr = [[UIScrollView alloc] init];
    scr.contentSize = CGSizeMake(kScreenWidth - 20, 800);
    scr.backgroundColor = [UIColor colorWithRed:241/255.0 green:242/255.0 blue:243/255.0 alpha:1];
    [self.view addSubview:scr];
    [scr mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.view.mas_top).mas_offset(10);
        make.left.equalTo(self.view.mas_left).mas_offset(10);
        make.right.equalTo(self.view.mas_right).mas_offset(-10);
        make.bottom.equalTo(self.view.mas_bottom);
        
    }];
    
//工作团队列表
    UITableView *tab = [[UITableView alloc] init];
    self.tab = tab;
    tab.delegate = self;
    tab.dataSource = self;
    tab.backgroundColor = [UIColor whiteColor];
    [scr addSubview:tab];
    
    [tab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(scr.mas_top);
        make.left.equalTo(self.view.mas_left).mas_offset(10);
        make.right.equalTo(self.view.mas_right).mas_offset(-10);
        make.height.equalTo(@200);
    }];
    
//工作方案
    UITableView *tab2 = [[UITableView alloc] init];
    self.tab2 = tab2;
    tab2.delegate = self;
    tab2.dataSource = self;
    tab2.backgroundColor = [UIColor whiteColor];
    [scr addSubview:tab2];
    [tab2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(tab.mas_bottom).mas_offset(30);
        make.left.equalTo(self.view.mas_left).mas_offset(10);
        make.right.equalTo(self.view.mas_right).mas_offset(-10);
        make.height.equalTo(@166);
    }];
    
//宣传工作
    UITableView *tab3 = [[UITableView alloc] init];
    self.tab3 = tab3;
    tab3.delegate = self;
    tab3.dataSource = self;
    tab3.backgroundColor = [UIColor whiteColor];
    [scr addSubview:tab3];
    [tab3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(tab2.mas_bottom).mas_offset(30);
        make.left.equalTo(self.view.mas_left).mas_offset(10);
        make.right.equalTo(self.view.mas_right).mas_offset(-10);
        make.height.equalTo(@166);
    }];
    
    
    [self loadData];
    [self loadData2];
    [self loadData3];
}

- (void)loadData{

    NSString * userId = [[NSUserDefaults standardUserDefaults]objectForKey:@"userId"];
    NSString * pwdId = [[NSUserDefaults standardUserDefaults]objectForKey:@"pwdId"];
    NSString * userHumber = [[NSUserDefaults standardUserDefaults]objectForKey:@"userHumber"];
    
    NSString * json  = [NSString stringWithFormat:@"{'action': gztdMch,'service': DXMService, 'userName':'%@','password':'%@', 'vaueJson':'{userid :%@,id:%@}'}",userId,pwdId,userHumber,self.ID];
    
    NSArray * array = @[@{@"arg0":json}];
    
    [HttpTools requestWithURL:BaseURL arrays:array method:Basemethod success:^(id JSON) {

            NSArray *dictArr = JSON[@"reason"];
            
            if (dictArr.count) {
                
                for (NSDictionary *dict in dictArr) {
                    
                    NSDictionary *dict2 = dict[@"attrs"];
                    
                    WorkModel *model = [WorkModel mj_objectWithKeyValues:dict2];
                    
                    [self.dataArray addObject:model];
                }
                
            }
            
            [self.tab reloadData];
        
    } failure:^(NSError *error) {
        
        
    }];

}
- (void)loadData2{
    
    NSString * userId = [[NSUserDefaults standardUserDefaults]objectForKey:@"userId"];
    NSString * pwdId = [[NSUserDefaults standardUserDefaults]objectForKey:@"pwdId"];
    NSString * userHumber = [[NSUserDefaults standardUserDefaults]objectForKey:@"userHumber"];
    
    NSString * json  = [NSString stringWithFormat:@"{'action': gzfaMch,'service': DXMService, 'userName':'%@','password':'%@', 'vaueJson':'{userid :%@,id:%@}'}",userId,pwdId,userHumber,self.ID];
    
    NSArray * array = @[@{@"arg0":json}];
    
    [HttpTools requestWithURL:BaseURL arrays:array method:Basemethod success:^(id JSON) {
        
        NSArray *arr = JSON[@"reason"];
        
        if (arr.count) {
            
            for (NSDictionary *dict in arr) {
                
                NSDictionary *dict2 = dict[@"attrs"];
                
                WorkModel *model = [WorkModel mj_objectWithKeyValues:dict2];
                
                [self.dataArray1 addObject:model];
            }
        }
        
        [self.tab2 reloadData];
        
    } failure:^(NSError *error) {
        
        
    }];
    
}

- (void)loadData3{
    
    NSString * userId = [[NSUserDefaults standardUserDefaults]objectForKey:@"userId"];
    NSString * pwdId = [[NSUserDefaults standardUserDefaults]objectForKey:@"pwdId"];
    NSString * userHumber = [[NSUserDefaults standardUserDefaults]objectForKey:@"userHumber"];
    
    NSString * json  = [NSString stringWithFormat:@"{'action': xcfaMch,'service': DXMService, 'userName':'%@','password':'%@', 'vaueJson':'{userid :%@,id:%@}'}",userId,pwdId,userHumber,self.ID];
    
    NSArray * array = @[@{@"arg0":json}];
    
    [HttpTools requestWithURL:BaseURL arrays:array method:Basemethod success:^(id JSON) {
        
        NSArray *arr = JSON[@"reason"];
        
        if (arr.count) {
            
            for (NSDictionary *dict in arr) {
                
                NSDictionary *dict2 = dict[@"attrs"];
                
                AdvertisePlan *model = [AdvertisePlan mj_objectWithKeyValues:dict2];
                
                [self.dataArray2 addObject:model];
            }
        }
        
        [self.tab3 reloadData];
        
    } failure:^(NSError *error) {
        
        
    }];
    
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    if (tableView == self.tab) {
        return self.dataArray.count;

    }else if(tableView == self.tab2){
    
        return self.dataArray1.count;
    }else{
    
        return self.dataArray2.count;
    }

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    

    if (tableView == self.tab) {
        WorkModel *model = self.dataArray[indexPath.row];

        WorkTeamCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
        
        if (cell == nil) {
            cell = [WorkTeamCell WithWorkTeamCell];
        }
        
        cell.model = model;
        
        return cell;

    }else if(tableView == self.tab2){
        WorkModel *model = self.dataArray1[indexPath.row];

        WorkPlanCell *cell = [tableView dequeueReusableCellWithIdentifier:ID2];
    
        if (cell == nil) {
            cell = [WorkPlanCell WithWorkPlanCell];
        }
        
        cell.model = model;
        
        return cell;
    }else{
        AdvertisePlan *model = self.dataArray2[indexPath.row];
        
        AdvertisePlanCell *cell = [tableView dequeueReusableCellWithIdentifier:ID3];
    
        if (cell == nil) {
            
            cell = [AdvertisePlanCell WithAdvertisePlanCell];
        }
    
        cell.model = model;
        
        return cell;
    }
    
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{

    if (tableView == self.tab) {
        UIView *bgV = [[UIView alloc] initWithFrame:CGRectMake(0, 0,kScreenWidth, 40)];
        
        UIView *colorV = [[UIView alloc] initWithFrame:CGRectMake(10, 10, 3, 10)];
        colorV.backgroundColor = [UIColor blueColor];
        [bgV addSubview:colorV];
        
        UILabel *lbl = [[UILabel alloc] init];
        lbl.text = @"工作团队";
        lbl.textColor = [UIColor blueColor];
        lbl.font = [UIFont systemFontOfSize:15];
        [bgV addSubview:lbl];
        
        [lbl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(bgV.mas_top);
            make.left.equalTo(colorV.mas_right).mas_offset(5);
            make.right.equalTo(bgV.mas_right).mas_offset(-5);
            make.bottom.equalTo(bgV.mas_bottom).mas_offset(-10);
        }];
        return bgV;
    }else if (tableView == self.tab2){
        UIView *bgV = [[UIView alloc] initWithFrame:CGRectMake(0, 0,kScreenWidth, 40)];
        
        UIView *colorV = [[UIView alloc] initWithFrame:CGRectMake(10, 10, 3, 10)];
        colorV.backgroundColor = [UIColor blueColor];
        [bgV addSubview:colorV];
        
        UILabel *lbl = [[UILabel alloc] init];
        lbl.text = @"工作方案";
        lbl.textColor = [UIColor blueColor];
        lbl.font = [UIFont systemFontOfSize:15];
        [bgV addSubview:lbl];
        
        [lbl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(bgV.mas_top);
            make.left.equalTo(colorV.mas_right).mas_offset(5);
            make.right.equalTo(bgV.mas_right).mas_offset(-5);
            make.bottom.equalTo(bgV.mas_bottom).mas_offset(-10);
        }];
        return bgV;
    }else{
        UIView *bgV = [[UIView alloc] initWithFrame:CGRectMake(0, 0,kScreenWidth, 40)];
        
        UIView *colorV = [[UIView alloc] initWithFrame:CGRectMake(10, 10, 3, 10)];
        colorV.backgroundColor = [UIColor blueColor];
        [bgV addSubview:colorV];
        
        UILabel *lbl = [[UILabel alloc] init];
        lbl.text = @"宣传工作";
        lbl.textColor = [UIColor blueColor];
        lbl.font = [UIFont systemFontOfSize:15];
        [bgV addSubview:lbl];
        
        [lbl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(bgV.mas_top);
            make.left.equalTo(colorV.mas_right).mas_offset(5);
            make.right.equalTo(bgV.mas_right).mas_offset(-5);
            make.bottom.equalTo(bgV.mas_bottom).mas_offset(-10);
        }];
        return bgV;
    }
    
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 40;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    if (tableView == self.tab) {
        return 207;
    }else if(tableView == self.tab2){
        return 123;
    }else{
        return 123;
    }
}


@end













